package com.xsoft.demo9;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import java.text.SimpleDateFormat;
import java.util.Date;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private ViewPager viewPager;
    private LinearLayout home;
    private LinearLayout my;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Utils.selectDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        findViewById(R.id.holiday).setOnClickListener(this);
        findViewById(R.id.schedule).setOnClickListener(this);
        viewPager = findViewById(R.id.view_pager);
        home = (LinearLayout) findViewById(R.id.home);
        home.setOnClickListener(this);
        my = (LinearLayout) findViewById(R.id.my);
        my.setOnClickListener(this);
        onClick(home);
        MyViewPagerAdapter adapter = new MyViewPagerAdapter();
        adapter.addViews(new CalendarItemView(this));
        adapter.addViews(new CalendarItemView(this));
        adapter.addViews(new CalendarItemView(this));
        viewPager.setAdapter(adapter);
        viewPager.setCurrentItem(1000);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.holiday:
                Utils.showHoliday = !Utils.showHoliday;
                sendBroadcast(new Intent(Utils.ACTION_UPDATE_CALENDAR));
                break;
            case R.id.schedule:
                startActivity(new Intent(this, ScheduleActivity.class));
                break;
            case R.id.home:
                home.setSelected(true);
                my.setSelected(false);
                break;
            case R.id.my:
                home.setSelected(false);
                my.setSelected(true);
                break;
        }
    }
}